<?php
/**
 * Admin_Form_AddUser - Formulář pro přídání uživatele (možné využití i pro editaci)
 *
 * @author Petr Laslo
 * @license MIT License
 * @package Knihovna\Modules\Admin\Forms
 * @link https://code.google.com/p/knihovna/
 */

class Admin_Form_AddUser extends Zend_Form
{
    /**
     * Inicializuje formulář
     *
     * @author Petr Laslo
     */
    public function init()
    {
        $this->addElementPrefixPath(
                'Knihovna_Validate',
                'Knihovna/Validate',
                'validate'
            );

        //načte uživatelské role z ACL
        $roles = new Knihovna_Model_DbTable_Usersrole();
        $roleslist = $roles->fetchArray();

       $userName     = new Zend_Form_Element_Text('user_name',
            array('size'     => 15,
                'maxlength'=> 20,
                'label'    => 'Uživatelské jméno',
                'require'  => true));
        $userPassword = new Zend_Form_Element_Password('user_password', array('label'  => 'Heslo',
            'require'=> true));
        $userPassword2 = new Zend_Form_Element_Password('user_password2', array('label'  => 'Heslo znovu',
            'require'=> true));


        $userRole     = new Zend_Form_Element_Select ('user_role');
        $userRole->setLabel('Role');
        $userRole->setMultiOptions($roleslist);


        $send = new Zend_Form_Element_Submit('submit_add','Přidat');

        $userName->addValidator('NotEmpty',true);
        $userName->addValidator('UserNameUnique',true);
        $userPassword->addValidator('NotEmpty',true);
        $userPassword->addValidator('EqualInput', true, array('user_password2'));


        $userName->addValidator('StringLength', true, array(4, 64));
        $userPassword->addValidator('StringLength', true, array(5, 64));


        $userName->addFilter('StringTrim');
        $userName->addFilter('StripTags');
        $userPassword->addFilter('StringTrim');

        $this->addElements(array($userName, $userPassword, $userPassword2, $userRole, $send));
    }


}

